import axios from 'axios';

const service = axios.create({
    // process.env.NODE_ENV === 'development' 来判断是否开发环境
    // easy-mock服务挂了，暂时不使用了
    baseURL: 'http://localhost:9998/',
    timeout: 5000
});
//this.$axios
// 					.post(
// 						"http://localhost:8888/nursing/bed/add",
// 						this.$qs.stringify(this.form)
// 					)
//			update(index, row) {
// 				this.dialogVisible = true;
// 				this.$axios.get("http://localhost:8888/nursing/bed/bed", {
// 						params: {
// 							id: row.id
// 						}
// 					})
// 					.then((res) => {
// 						this.form = res.data
// 					})
// 			},
service.interceptors.request.use(
    config => {
        //设置请求头 【文件类型】 1.18添加
        // config.headers['Content-Type'] = 'application/json;charset=utf-8';
        //携带的token 1.18添加
        config.headers['token'] = localStorage.getItem("token");
        return config;
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);
// //导航守卫
// const router = new Router
// router.beforeEach((to,from,next)=>{
//     alert(to.path)
//     if (to.path==='#/login') return next();
//     //获取token
//     const tokenStr= localStorage.getItem("token");
//     if(!tokenStr) {
//         router.push("/login");
//         // return next('/login')
//     }
//     next()
//
// })
service.interceptors.response.use(
    response => {
        if (response.status === 200) {
            return response.data;
        } else {
            Promise.reject();
        }
    },
    error => {
        console.log(error);
        return Promise.reject();
    }
);

service.defaults.withCredentials = true

export default service;
